#pragma once
#include <iostream>
#include <vector>
#include <string>
#include <ctemplate/template.h>
#include "oj_model.hpp"



namespace viewNs {
    const std::string all_questions_path = "./wwwroot/all_questions.html";
    const std::string one_question_path = "./wwwroot/one_question.html";
    using namespace modelNs;
    class View {
    public :
        // 渲染所有题目列表的网页
        void ExpandAllHtml(const std::vector<Question>& allquestions, std::string* out_html) {
            ctemplate::TemplateDictionary root("all_questions");
            for (auto& q : allquestions) {
                // 获取一个子字典
                ctemplate::TemplateDictionary *sub = root.AddSectionDictionary("question_list");
                sub->SetValue("number", q._number);
                sub->SetValue("title", q._title);
                sub->SetValue("star", q._star);
            }
            // 获取被渲染的网页对象
            ctemplate::Template *tpl = ctemplate::Template::GetTemplate(all_questions_path, ctemplate::Strip::DO_NOT_STRIP);

            // 添加数据字典到网页当中(即开始渲染)
            tpl->Expand(out_html, &root);
        }

        // 渲染单个题目的网页
        void ExpandOneHtml(const Question& question, std::string* out_html) {
            ctemplate::TemplateDictionary root("one_question");
            root.SetValue("number", question._number);
            root.SetValue("title", question._title);
            root.SetValue("desc", question._desc);
            root.SetValue("pre_code", question._header);
            root.SetValue("start", question._star);

            // 获取被渲染的网页对象
            ctemplate::Template *tpl = ctemplate::Template::GetTemplate(one_question_path, ctemplate::Strip::DO_NOT_STRIP);

            // 添加数据字典到网页当中(即开始渲染)
            tpl->Expand(out_html, &root);
            
        }

        

    private :
    };

};